<%--
    Document   : listPostRelationships
    Created on : Apr 27, 2014, 4:47:58 PM
    Author     : Anton Strack
--%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="csd" tagdir="/WEB-INF/tags" %>
<%@tag description="Lists the related posts passed on the recentPosts attribute " pageEncoding="UTF-8"%>
<%@attribute name="relatedPosts" type="java.util.List<csdwa.Post>"%>
<%@attribute name="emptyMessage" required="true"%>
<%@attribute name="relationshipTitle" required="true"%>
<%@attribute name="relationshipId" required="true"%>
<%@attribute name="postType" required="true"%>

<div class="panel panel-default">
    <div class="panel-heading">
        <h4 class="panel-title">
            <a data-toggle="collapse" href="#${relationshipId}RelationshipCollapse">
                <c:choose>
                    <c:when test="${relatedPosts != null && relatedPosts.size() > 0}">
                        ${relatedPosts.size()}
                    </c:when>
                    <c:otherwise>
                        0
                    </c:otherwise>
                </c:choose>
                ${relationshipTitle} Relationships<b class="caret"></b>
            </a>
        </h4>
    </div>
    <div id="${relationshipId}RelationshipCollapse" class="panel-collapse collapse">
        <div class="panel-body csd_relationship_group">
            <p><a href="${req.contextPath}?action=add&resource=relationship&id=${relationshipId}&for=${postType}&sid=${bean.id}&name=${bean.name}">Add ${relationshipTitle}</a></p>
            <ul class="${postType}_${relationshipId}_relationship">
                <c:choose> <%-- http://localhost:8084/Site?action=remove&resource=relationship&id=11&for=plot&sid=58&tid=2 --%>
                    <c:when test="${relatedPosts != null && relatedPosts.size() > 0}">
                        <c:forEach items="${relatedPosts}" var="relatedPost" >
                            <li class="list-group-item ${postType}_${relationshipId}"><a href="${req.contextPath}?action=view&resource=${relatedPost.getDerivedValue('PostATypeName')}&id=${relatedPost.postAId}">${relatedPost.getDerivedValue('PostAName')}</a> is ${relatedPost.getDerivedValue('RelationshipTypeName')} of <a href="${req.contextPath}?action=view&resource=${relatedPost.getDerivedValue('PostBTypeName')}&id=${relatedPost.postBId}">${relatedPost.getDerivedValue('PostBName')}</a> - <a href="${req.contextPath}?action=remove&resource=relationship&id=${relationshipId}&for=${postType}&sid=${relatedPost.id}&tid=${bean.id}">Remove relationship</a><br />
                            </li>
                        </c:forEach>
                    </c:when>
                    <c:otherwise>
                        <li class="list-group-item">${emptyMessage}</li>
                        </c:otherwise>
                    </c:choose>
            </ul>
        </div>
    </div>
</div>




